<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php echo $this->breadCrumbs(); ?>
  </div>
  <?php if (isset($error_warning)) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/product.png" alt="" /> <?php echo $_['heading_title']; ?></h1>
      <div class="buttons">
		<span style="margin-right:5px;">
		<select onchange="filter()" name="filter_category_id">
			<option value="*"> [ Category ] </option>
			<?php echo form_select_option($categories, $filter_category_id, null, 'category_id', 'name');?>
		</select>
		<select onchange="filter()" name="filter_supplier_id">
			<option value="*"> [ Supplier ] </option>
			<?php echo form_select_option($suppliers, $filter_supplier_id, true);?>
		</select>
		</span>
		<!--  |
		<?php echo $_['column_status']; ?>:
		<select name="switch" onchange="$('#status').val(this.value);">
			<option></option>
			<option value="1"><?php echo $_['text_enabled'];?></option>
			<option value="0"><?php echo $_['text_disabled'];?></option>
		</select>
		<a onclick="$('#form').attr('action', '<?php echo UA('catalog/product/update_status'); ?>'); $('#form').submit();" class="button"><?php echo $_['button_update']; ?></a-->
		 |
		<a href="<?php echo UA('catalog/product/insert'); ?>" class="button"><?php echo $_['button_insert']; ?></a>
		<a onclick="$('#form').attr('action', '<?php echo UA('catalog/product/copy'); ?>'); $('#form').submit();" class="button"><?php echo $_['button_copy']; ?></a>
		<a onclick="$('form').submit();" class="button"><?php echo $_['button_delete']; ?></a></div>
    </div>
    <div class="content">
      <form action="<?php echo UA('catalog/product/delete'); ?>" method="post" id="form">
		<input type="hidden" name="status" id="status" value="1">
        <table class="J_tablelist list" data-acturi="<?php echo UA('catalog/product/smartedit');?>">
          <thead>
            <tr>
              <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
              <td class="center"><?php echo $_['column_image']; ?></td>
              <td class="left">
                <a <?php echo sort_url('pd.name'); ?>><?php echo $_['column_name']; ?></a>
              </td>
              <td class="left">
                <a <?php echo sort_url('p.model'); ?>><?php echo $_['column_model']; ?></a>
              </td>
              <td class="left"><a <?php echo sort_url('p.msrp'); ?>><?php echo $_['column_msrp']; ?></a></td>
              <td class="left"><a <?php echo sort_url('p.cost'); ?>><?php echo $_['column_cost']; ?></a></td>
              <td class="left">
                <a <?php echo sort_url('p.price'); ?>><?php echo $_['column_price']; ?></a>
              </td>
              <td class="right">
                <a <?php echo sort_url('p.quantity'); ?>><?php echo $_['column_quantity']; ?></a>
               </td>
               <td class="left">
                <a <?php echo sort_url('p.featured'); ?>><?php echo $_['column_featured']; ?></a>
              </td>
              <td class="left">
                <a <?php echo sort_url('p.status'); ?>><?php echo $_['column_status']; ?></a>
              </td>
              <td class="left">
                <a <?php echo sort_url('p.sort_order'); ?>><?php echo $_['column_sort_order']; ?></a>
              </td>
              <td class="left">
                <a <?php echo sort_url('p.sold'); ?>><?php echo $_['column_sold']; ?></a>
              </td>
              <td class="right"><?php echo $_['column_action']; ?></td>
            </tr>
           </thead>
           <tbody>
            <tr class="filter">
              <td></td>
              <td></td>
              <td><input type="text" name="filter_name" value="<?php echo $filter_name; ?>"  size="25"/></td>
              <td><input type="text" name="filter_model" value="<?php echo $filter_model; ?>" size="12"/></td>
              <td></td>
              <td></td>
              <td align="left"><input type="text" name="filter_price" value="<?php echo $filter_price; ?>" size="5"/></td>
              <td align="right"><input type="text" name="filter_quantity" value="<?php echo $filter_quantity; ?>" style="text-align: right;"  size="5"/></td>
              <td><select name="filter_featured">
                  <option value="*"></option>
				  <?php echo form_select_option($_['option_yesno'], $filter_featured, true);?>
                </select></td>
              <td><select name="filter_status">
                  <option value="*"></option>
				  <?php echo form_select_option($_['option_statuses'], $filter_status, true);?>
                </select></td>
              <td></td>
              <td></td>
              <td align="right"><a onclick="filter();" class="button"><?php echo $_['button_filter']; ?></a></td>
            </tr>
          </tbody>
          <tbody class="J_tbody_cm">
            <?php if ($products) { ?>
            <?php foreach ($products as $product) { ?>
			<tr onmouseover="$(this).addClass('on');" onmouseout="$(this).removeClass('on');"
				data-id="<?php echo $product['product_id'];?>" <?php if ($product['style']) echo 'class="mark_style', $product['style'], '"';?>>
              <td style="text-align: center;">
                <input type="checkbox" name="selected[]" value="<?php echo $product['product_id']; ?>" />
              </td>
              <td class="center">
			  <a class="powerfloat" href="<?php echo $product['image']; ?>">
			  <img src="<?php echo $product['image']; ?>" alt="<?php echo $product['name']; ?>" style="padding: 1px; border: 1px solid #DDDDDD; width:40px" />
			  </a>
			  </td>
              <td class="left">
				
				<span class="product-name" data-tdtype="textarea" data-field="name" data-id="<?php echo $product['product_id']; ?>"><?php echo $product['name']; ?></span>
				  <?php if (!empty($product['source_link'])) { ?>
					  <a href="<?php echo $product['source_link'];?>" title="source link" target="_blank"><img src="view/image/link_go.png"></a>
				  <?php } ?>
				  <?php if (!empty($product['note'])) {?>
				  <a id="note-<?php echo $product['product_id']; ?>" onclick="showNoteDialog('product', <?php echo $product['product_id'];?>)">
				    <img src="view/image/note.png" />
				  	<span class="none"><?php echo $product['note'];?></span>
				  </a>
				  <?php } else { ?>
				  <a id="note-<?php echo $product['product_id']; ?>" onclick="showNoteDialog('product', <?php echo $product['product_id'];?>)"></a>
				  <?php } ?>
				<br>
				<small>
				<a href="<?php echo $product['href'];?>" target="_blank">viewed:<?php echo $product['viewed'];?></a>,
				<a href="<?php echo UA('catalog/review', '&filter_reset=1&filter_product_id=' . $product['product_id']);?>" target="_blank"><img src="../themes/default/image/stars-<?php echo $product['rating']; ?>.png" height="10"/> (<?php echo $product['reviews']; ?>)</a>
				</small>

			  </td>
              <td class="left"><span data-tdtype="edit" data-field="model" data-id="<?php echo $product['product_id'];?>"><?php echo $product['model']; ?></span></td>
              <td class="left"><span data-tdtype="edit" data-field="msrp" data-id="<?php echo $product['product_id'];?>"><?php echo $product['msrp']; ?></span></td>
              <td class="left"><span data-tdtype="edit" data-field="cost" data-id="<?php echo $product['product_id'];?>"><?php echo $product['cost']; ?></span></td>
              <td class="left"><?php if ($product['special']) { ?>
                <font style="text-decoration: line-through;">
                <span data-tdtype="edit" data-field="price" data-id="<?php echo $product['product_id'];?>"><?php echo $product['price']; ?></span>
                </font><br/>
                <font style="color: #b00;">
                	<?php echo $product['special']; ?>
                </font>
                	<?php if ($product['promotion']) { ?><em class="badge"><?php echo $product['promotion']; ?></em><?php } ?>
                <?php } else { ?>
                <span data-tdtype="edit" data-field="price" data-id="<?php echo $product['product_id'];?>"><?php echo $product['price']; ?></span>
                <?php } ?>
				</td>
              <td class="right"><?php if ($product['quantity'] <= 0) { ?>
                <font style="color: #FF0000;">
                <span data-tdtype="edit" data-field="quantity" data-id="<?php echo $product['product_id'];?>"><?php echo $product['quantity']; ?></span>
                </font>
                <?php } elseif ($product['quantity'] <= 5) { ?>
                <font style="color: #FFA500;">
                <span data-tdtype="edit" data-field="quantity" data-id="<?php echo $product['product_id'];?>"><?php echo $product['quantity']; ?></span>
                </font>
                <?php } else { ?>
                <font style="color: #008000;">
                <span data-tdtype="edit" data-field="quantity" data-id="<?php echo $product['product_id'];?>"><?php echo $product['quantity']; ?></span>
                </font>
                <?php } ?></td>
               <td class="center"><img class="cur" src="view/image/<?php echo $product['featured'] ? 'enabled' : 'disabled'; ?>.png" data-tdtype="toggle" data-field="featured" data-id="<?php echo $product['product_id'];?>" data-value="<?php echo $product['featured']; ?>"></td>
              <td class="center"><img class="cur" src="view/image/<?php echo $product['status'] ? 'enabled' : 'disabled'; ?>.png" data-tdtype="toggle" data-field="status" data-id="<?php echo $product['product_id'];?>" data-value="<?php echo $product['status']; ?>"></td>
              <td class="left"><span data-tdtype="edit" data-field="sort_order" data-id="<?php echo $product['product_id'];?>"><?php echo $product['sort_order']; ?></span></td>
              <td class="left"><span data-tdtype="edit" data-field="sold" data-id="<?php echo $product['product_id'];?>"><?php echo $product['sold']; ?></span></td>
              <td class="right">
                [ <a href="<?php echo UA('catalog/product/update', 'product_id=' . $product['product_id']); ?>"><?php echo $_['text_edit']; ?></a> ]
              </td>
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="15"><?php echo $_['text_no_results']; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<div id="contextMenu" class="contextMenu">
<ul>
<li id="note"><?php echo $_['cm_add_note']; ?></li>
<li id="style1"><span class="mark_style1"><?php echo $_['cm_mark_style1']; ?></span></li>
<li id="style2"><span class="mark_style2"><?php echo $_['cm_mark_style2']; ?></span></li>
<li id="style3"><span class="mark_style3"><?php echo $_['cm_mark_style3']; ?></span></li>
<li id="style4"><span class="mark_style4"><?php echo $_['cm_mark_style4']; ?></span></li>
<li id="style5"><span class="mark_style5"><?php echo $_['cm_mark_style5']; ?></span></li>
<li id="remove">Remove Style</li>
</ul>
</div>
<script src="<?php echo ROOT;?>static/javascript/jquery/jquery.contextmenu.min.js"></script>
<script type="text/javascript"><!--
function filter() {
	url = '<?php echo UA('catalog/product', 'filter_reset=1'); ?>';

	var v = $('input[name=\'filter_name\']').attr('value');
	if (v) {
		url += '&filter_name=' + encodeURIComponent(v);
	}

	v = $('input[name=\'filter_model\']').attr('value');
	if (v) {
		url += '&filter_model=' + encodeURIComponent(v);
	}

	v = $('input[name=\'filter_price\']').attr('value');
	if (v) {
		url += '&filter_price=' + encodeURIComponent(v);
	}

	v = $('input[name=\'filter_quantity\']').attr('value');
	if (v) {
		url += '&filter_quantity=' + encodeURIComponent(v);
	}
	v = $('select[name=\'filter_featured\']').attr('value');
	if (v != '*') {
		url += '&filter_featured=' + encodeURIComponent(v);
	}
	v = $('select[name=\'filter_status\']').attr('value');
	if (v != '*') {
		url += '&filter_status=' + encodeURIComponent(v);
	}

	v = $('select[name=\'filter_category_id\']').attr('value');
	if (v != '*') {
		url += '&filter_category_id=' + encodeURIComponent(v);
	}

	v = $('select[name=\'filter_supplier_id\']').attr('value');
	if (v != '*') {
		url += '&filter_supplier_id=' + encodeURIComponent(v);
	}
	location = url;
}
//--></script>
<script type="text/javascript"><!--
$('#form input').keydown(function(e) {
	if (e.keyCode == 13) {
		filter();
	}
});
//--></script>
<script type="text/javascript"><!--
$('input[name=\'filter_name\']').autocomplete({
	delay: 500,
	source: function(request, response) {
		$.ajax({
			url: '<?php echo UA('catalog/product/autocomplete'); ?>&filter_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {
				response($.map(json, function(item) {
					return {
						label: item.name,
						value: item.product_id
					}
				}));
			}
		});
	},
	select: function(event, ui) {
		$('input[name=\'filter_name\']').val(ui.item.label);

		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});

$('input[name=\'filter_model\']').autocomplete({
	delay: 500,
	source: function(request, response) {
		$.ajax({
			url: '<?php echo UA('catalog/product/autocomplete'); ?>&filter_model=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {
				response($.map(json, function(item) {
					return {
						label: item.model,
						value: item.product_id
					}
				}));
			}
		});
	},
	select: function(event, ui) {
		$('input[name=\'filter_model\']').val(ui.item.label);
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});

$(".powerfloat").powerFloat({targetMode: "ajax", targetAttr: "href", position: "3-4" });
$('.J_tablelist').listTable();
$('.J_tbody_cm tr').contextMenu('contextMenu', {
	bindings: {
		'note': function(tr) {showNoteDialog('product', $(tr).attr('data-id'));},
		'style1': function(tr) {
			$(tr).addClass('mark_style1');
			markStyle('product', $(tr).attr('data-id'), 1);
		},
		'style2': function(tr) {
			$(tr).addClass('mark_style2');
			markStyle('product', $(tr).attr('data-id'), 2);
		},
		'style3': function(tr) {
			$(tr).addClass('mark_style3');
			markStyle('product', $(tr).attr('data-id'), 3);
		},
		'style4': function(tr) {
			$(tr).addClass('mark_style4');
			markStyle('product', $(tr).attr('data-id'), 4);
		},
		'style5': function(tr) {
			$(tr).addClass('mark_style5');
			markStyle('product', $(tr).attr('data-id'), 5);
		},
		'remove': function(tr) {
			$(tr).removeClass();
			markStyle('product', $(tr).attr('data-id'), 0);
		}
	}
});
//--></script>
<?php echo $footer; ?>